<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
	
	String type = (String)request.getAttribute("type");
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>商家充值</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<jsp:include page="/page/head.jsp"></jsp:include>
	<script type="text/javascript">
		var type = "<%=type%>";
		
		function save(){
			if($('#fm').form('validate')){
				var url =  path;
				url +=  "/rechargeInfo/save.do?t="+new Date().getTime();
				url += "&type="+type;
				
				var data = "&amount="+escape(escape($('#amount').val()));
				data += "&score="+escape(escape($('#score').val()));
				data += "&isRebate="+escape(escape($('#isRebate').val()));
				
				$.ajax({
				  url: url,
				  data:data,
				  success: function(data) {
					   if(data == "1"){
						   window.location = path+"/rechargeInfo/rechargeInfoMgr.do";
					   }else{
						   alertBox("操作失败！");
					   }
				  }
				});
				
			}
		}
		
		function autoSetScore(){
			if($('#isRebate').val() == 1){
				return;
			}
			var amount = $('#amount').val();
			var autoScore = amount*10;
			$('#score').numberbox('setValue',autoScore);
		}
		
		function isAppoint(){
	 		if(document.getElementById("appoint").checked){
	 			$('#score').numberbox('enable');
	 			$('#isRebate').attr('value',1);
	 		}else{
	 			$('#score').numberbox('disable');
	 			$('#score').numberbox('setValue',($('#amount').val())*10);
	 			$('#isRebate').attr('value',2);
	 		}
	 	}
		
		function callback(){
			window.location = path+"/rechargeInfo/rechargeInfoMgr.do";
		}
		
		$.extend($.fn.validatebox.defaults.rules, {  
			amount:{                                      
				//充值金额只能为100的倍数
		    	validator: function (value) {
		    		return value%100 == 0;
		        },
		        message: '充值金额只能为100的倍数!'
		    }
		});
	</script>
  </head>
  
  <body>
   <div class="right">
	<h1><b>${type=='manualRecharge'?'手动充值':type=='alipayRecharge'?'支付宝充值':'网银充值' }</b><span><img src="<%=basePath%>images/right_h1bg2.jpg" width="3" height="29" /></span></h1>
	<form id="fm">
	<div class="ri_main">
		<table width="97%" border="0" cellspacing="1" cellpadding="8" style="background:#d9d9d9;">
			<tr>
			    <td width="15%" align="left" bgcolor="#FFFFFF">充值商家：</td>
				<td width="35%" align="left" bgcolor="#FFFFFF">${orgName}
					<input type="hidden" id="orgId" name="orgId" value="${orgId }">
					<input type="hidden" id="orgType" name="orgType" value="${orgType }">
				</td>
				<td width="15%" align="left" bgcolor="#FFFFFF">法人代表：</td>
				<td width="35%" align="left" bgcolor="#FFFFFF">${truename}</td>
			</tr>
			<tr>
				<td align="left" bgcolor="#FFFFFF">剩余积分：</td>
				<td align="left" bgcolor="#FFFFFF" colspan="3">${sscore}</td>
			</tr>
			<tr>
				<td align="left" bgcolor="#FFFFFF">充值金额：</td>
			    <td bgcolor="#FFFFFF" colspan="3">
					<input validType="amount" id="amount" name="amount" onblur="autoSetScore()" class="easyui-numberbox" precision="2" required="true" style="width:200px;">
					100,200,300...
			    </td>
			</tr>
			<tr>
				<td align="left" bgcolor="#FFFFFF">充值积分：</td>
			    <td bgcolor="#FFFFFF" colspan="3">
					<input id="score" name="score" class="easyui-numberbox" disabled="disabled" precision="2" required="true" style="width:200px;">
					<input type="checkbox" id="appoint" name="appoint" onclick="isAppoint()" />指定积分
					<input type="hidden" id="isRebate" name="isRebate" value="2"/>
			    </td>
			</tr>
		   
			<tr>
				<td align="center" bgcolor="#FFFFFF" colspan="4">
					<a href="javascript:void(0);" class="easyui-linkbutton" iconCls="icon-ok" onclick="save()">保存</a>
					<a href="javascript:void(0);" class="easyui-linkbutton" iconCls="icon-undo" onclick="callback()">取消</a>
				</td>
			</tr>
		</table>
	</div>
	</form>
	</div>
  </body>
</html>
